import { DefaultStage } from "../default-stage";
import { RawAssetsUrl } from "../../raw-assets-info";
import { AssetsLoad } from "three-lib/loader/assets-load";
import { BoxGeometry, Color, Mesh, MeshBasicMaterial, MeshPhysicalMaterial, Scene, Vector3 } from "three";
import { Random } from 'three-lib/tool/random';


class InitializeComponent {
    public static initialize(stage: DefaultStage): void {
        this.testAssets(stage);
    }

    private static testAssets(stage: DefaultStage): void {
        // stage.engine.setClearColor(new Color(1, 0, 0), 0.1)
        // stage.mainCamera.position.set(0, 0, 10);
        // stage.mainCamera.lookAt(new Vector3(0, 0, 0));
        const scene = stage.mainScene;
        scene.background = new Color(0, 0.1, 0);

        setInterval(() => {
            // stage.mainCamera.rotation.y += 0.01;
        }, 30);

        for (let i = 0; i < 100; i++) {
            const s = Random.float(0.2, 1);
            const g = new BoxGeometry(s, s, s);
            const m = new MeshBasicMaterial({ color: new Color(Random.float(0, 1), Random.float(0, 1), Random.float(0, 1)) });
            const box = new Mesh(g, m);
            scene.add(box);
            box.position.set(Random.float(-20, 20), Random.float(-20, 20), Random.float(-20, 20));
        }

        const loader = stage.loader;
        const model = loader.getMeshTaskInfo(RawAssetsUrl.changjing);
        scene.add(model!.data!.scene);

        //     const movie=loader.getVideoTextureTaskInfo(RawAssetsUrl.movie)?.texture!;
        //     const video=loader.getVideoTextureTaskInfo(RawAssetsUrl.video)?.texture!;

        //     const sound=loader.getAudioTaskInfo(RawAssetsUrl.music)?.sound!;
        //     sound.loop=true;

        //     const cubeTexture=loader.getHDRCubeTextureTaskInfo(RawAssetsUrl.hdrCube)!.texture!;
        //     // const cubeTexture=loader.getEquiRectangularCubeTextureTaskInfo(RawAssetsUrl.erCube)!.texture!;
        //     // const cubeTexture=loader.getCubeTextureTaskInfo(RawAssetsUrl.lightCubePX)!.texture!;
        //     cubeTexture.invertZ=true;

        //     const skyBox=MeshBuilder.CreateBox('box',{size:1},scene);
        //     const skyMat=new StandardMaterial('sky',scene);
        //     skyMat.backFaceCulling=false;
        //     skyMat.reflectionTexture=cubeTexture;
        //     skyMat.reflectionTexture.coordinatesMode=Texture.SKYBOX_MODE;
        //     skyMat.disableLighting=true;
        //     skyBox.material=skyMat;
        //     skyBox.position.z=4;

        //     const screen=MeshBuilder.CreatePlane('screen',{width:1,height:0.6},scene);
        //     const screenMat=new StandardMaterial('screen-mat',scene);
        //     screenMat.diffuseTexture=movie;
        //     screenMat.backFaceCulling=false;
        //     screen.material=screenMat;
        //     screen.position.x=4;

        //     const screen1=MeshBuilder.CreatePlane('screen',{width:1,height:0.6},scene);
        //     const screenMat1=new StandardMaterial('screen-mat1',scene);
        //     screenMat1.diffuseTexture=video;
        //     screenMat1.backFaceCulling=false;
        //     screen1.material=screenMat1;
        //     screen1.position.x=-4;

        //     stage.onUserGestureObservable.add((debut)=>{
        //         if(!debut)return;
        //         sound.play();
        //         movie.video.play();
        //         video.video.play();
        //     });
    }

}

export { InitializeComponent };
